import { createStore } from "vuex";
export default createStore({
  state: {
    user: JSON.parse(localStorage.getItem("user")) || {}, // 存放用户信息
    token: localStorage.getItem("token") || "", // 存放token
  },
  getters: {},
  mutations: {
    // 保存用户信息
    saveUserInfo(state, user) {
      // 存储在state中并存储在webstorage中
      state.user = user || {};
      localStorage.setItem("user", JSON.stringify(user));

    },
    // 保存token
    saveToken(state, token) {
      state.token = token || "";
      localStorage.setItem("token", token);
    }

  },
  actions: {},
  modules: {},
});
